﻿@* Generator: Template *@
@functions { public dynamic Model { get; set; } }@{
    var dotModule = Model.Module == null ? "" : ("." + Model.Module);
    var moduleDot = Model.Module == null ? "" : (Model.Module + ".");

    Func<EntityCodeField, string> gt = (f) => {
        if (f.Type == "String") {
            return "StringEditor";
        }
        else if (f.Type == "Int32" || f.Type == "Int16" || f.Type == "Int64") {
            return "IntegerEditor";
        }
        else if (f.Type == "Single" || f.Type == "Double" || f.Type == "Decimal") {
            return "DecimalEditor";
        }
        else if (f.Type == "DateTime") {
            return "DateEditor";
        }
        else if (f.Type == "Boolean") {
            return "BooleanEditor";
        }
        else
            return "StringEditor";
    };

    var fields = (IEnumerable<EntityCodeField>)Model.Fields;
    var fieldList = String.Join(", ", fields.Where(x => x.Name != Model.Identity)
        .Select(x => "['" + x.Ident + "', () => Serenity." + gt(x) + "]"));

}

namespace @(Model.RootNamespace)@(dotModule) {
    export class @(Model.ClassName)Form extends Serenity.PrefixedContext {
        static formKey = '@(moduleDot)@(Model.ClassName)';
    }

    export interface @(Model.ClassName)Form {@foreach (var x in Model.Fields)
    {
        if (x.Ident != Model.Identity)
        {<text>
        @(x.Ident): Serenity.@(gt(x));</text>}
    }

    }

    [@fieldList].forEach(x => Object.defineProperty(@(Model.ClassName)Form.prototype, <string>x[0], { get: function () { return this.w(x[0], (x[1] as any)()); }, enumerable: true, configurable: true }));
}